<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<input class="user_input" type="text" v-model="userName" placeholder="请输入您的昵称:" />
			<view class="login_btn">
				<tui-button type="green" shape="circle" width="200rpx" height="80rpx" @click="login"><text style="font-size: 30rpx;">登录</text></tui-button>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			userName: ''
		};
	},
	onLoad() {},
	methods: {
		async login() {
			if (!this.userName) {
				uni.showToast({
					title: '请填写用户名!',
					icon: 'none'
				});
				return;
			}
			const res = await this.$http('user.worker/login', {
				mobile: this.userName
			});
			if (res.code == 1) {
				uni.setStorageSync('userInfos', res.data);
				const connetRes = await this.$socket.connets();
				if (connetRes) {
					uni.reLaunch({
						url: '/pages/chat/msgList/msgList'
					});
				}
				uni.showToast({
					title: '登录失败！',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			uni.showToast({
				title: res.msg,
				icon: 'none',
				duration: 2000
			});
		}
	}
};
</script>

<style>
.content {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.logo {
	height: 200rpx;
	width: 200rpx;
	margin-top: 200rpx;
	margin-left: auto;
	margin-right: auto;
	margin-bottom: 50rpx;
}

.text-area {
	margin-top: 80px;
	text-align: center;
}
.user_input {
	border: 1px solid green;
	padding: 30rpx 20rpx;
	border-radius: 40px;
}
.login_btn {
	margin-top: 20rpx;
	display: flex;
	justify-content: center;
}

.title {
	font-size: 36rpx;
	color: #8f8f94;
}
</style>
